package com.shreecon.lms.persistancy;

import static com.shreecon.lms.interfaces.IMessageConstant.TECH_ERROR;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.shreecon.lms.interfaces.LMSException;
import com.shreecon.lms.interfaces.persistance.IEmployeeDAO;
import com.shreecon.lms.persistancy.hbm.EmployeeDetail;

/**
 * The Class EmployeeDAO.
 * 
 * @author Santhosh. Modified on Aug 13, 2011
 */
public class EmployeeDAO  extends ShreeConsDAO implements IEmployeeDAO{

	/* (non-Javadoc)
	 * @see com.shreecon.lms.interfaces.persistance.IEmployeeDAO#findByUserName(java.lang.String)
	 */
	public EmployeeDetail findByUserName(String userName) throws LMSException {
		Session session = HibernateAccessUtil.getInstance().getSession();
		EmployeeDetail employeeDetail = null;
		try {
			Criteria empCriteria = session.createCriteria(EmployeeDetail.class);
			empCriteria.add(Restrictions.eq("empUserName", userName));
			employeeDetail = (EmployeeDetail)empCriteria.uniqueResult();
		} catch (RuntimeException re) {
			throw new LMSException(TECH_ERROR,re);
		} finally{
			HibernateAccessUtil.getInstance().closeSession(session);
		}
		return employeeDetail;
	}
}
